var FoodModel = require('../models').Food;

module.exports = {
    addFoodItem: addFoodItem,
    delFoodItemByFoodId: delFoodItemByFoodId,
    modifyFoodItemByFoodItemId: modifyFoodItemByFoodItemId,
    getAllFoodItemsByMerchantId: getAllFoodItemsByMerchantId,
    getFoodItemByFoodItemId: getFoodItemByFoodItemId,
    getAllFoodItemsByFoodType:getAllFoodItemsByFoodType
}

function addFoodItem(merchant_id, food, callback) {

    var foodItem = new FoodModel(food);
    foodItem.merchant_id = merchant_id;
    foodItem.save(callback);
}

function delFoodItemByFoodId(foodItemId, callback) {
    FoodModel.remove({food_id: foodItemId}, callback);
}


function modifyFoodItemByFoodItemId(food, callback) {
    FoodModel.update({'food_id': food.food_id}, {
        $set:food
    }, callback);
}


function getFoodItemByFoodItemId(foodItemId, callback) {
    FoodModel.findOne({food_id: foodItemId}, callback);
}

function getAllFoodItemsByMerchantId(merchant_id, callback) {
    FoodModel.find({merchant_id: merchant_id}, callback);
}


function getAllFoodItemsByFoodType(foodType, merchant_id,callback) {
    FoodModel.find({foodType_name: foodType,merchant_id:merchant_id}, callback);
}